home *** CD-ROM | disk | FTP | other *** search
- package javax.swing;
-
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Dimension;
- import java.awt.Frame;
- import java.awt.Point;
- import java.awt.Rectangle;
- import java.awt.Toolkit;
- import java.awt.event.ActionListener;
- import java.awt.event.FocusListener;
- import java.awt.event.MouseAdapter;
- import java.awt.event.MouseEvent;
- import java.awt.event.MouseMotionListener;
- import java.util.EventObject;
-
- public class ToolTipManager extends MouseAdapter implements MouseMotionListener {
- Timer enterTimer = new Timer(750, new insideTimerAction(this));
- Timer exitTimer;
- Timer insideTimer;
- String toolTipText;
- Point preferredLocation;
- JComponent insideComponent;
- MouseEvent mouseEvent;
- boolean showImmediately;
- static final ToolTipManager sharedInstance = new ToolTipManager();
- Popup tipWindow;
- JToolTip tip;
- private Rectangle popupRect = null;
- private Rectangle popupFrameRect = null;
- boolean enabled = true;
- boolean mouseAboveToolTip = false;
- private boolean tipShowing = false;
- private long timerEnter = 0L;
- private KeyStroke postTip;
- private KeyStroke hideTip;
- private ActionListener postTipAction;
- private ActionListener hideTipAction;
- private FocusListener focusChangeListener = null;
- protected boolean lightWeightPopupEnabled = true;
- protected boolean heavyWeightPopupEnabled = false;
-
- ToolTipManager() {
- this.enterTimer.setRepeats(false);
- this.exitTimer = new Timer(500, new outsideTimerAction(this));
- this.exitTimer.setRepeats(false);
- this.insideTimer = new Timer(4000, new stillInsideTimerAction(this));
- this.insideTimer.setRepeats(false);
- this.postTip = KeyStroke.getKeyStroke(112, 2);
- this.postTipAction = new 1(this);
- this.hideTip = KeyStroke.getKeyStroke(27, 0);
- this.hideTipAction = new 2(this);
- }
-
- // $FF: synthetic method
- static FocusListener access$0(ToolTipManager var0) {
- return var0.focusChangeListener;
- }
-
- // $FF: synthetic method
- static FocusListener access$1(ToolTipManager var0) {
- return var0.createFocusChangeListener();
- }
-
- // $FF: synthetic method
- static void access$2(ToolTipManager var0, FocusListener var1) {
- var0.focusChangeListener = var1;
- }
-
- private FocusListener createFocusChangeListener() {
- return new 3(this);
- }
-
- static Frame frameForComponent(Component var0) {
- while(!(var0 instanceof Frame)) {
- var0 = ((Component)var0).getParent();
- }
-
- return (Frame)var0;
- }
-
- public int getDismissDelay() {
- return this.insideTimer.getInitialDelay();
- }
-
- private int getHeightAdjust(Rectangle var1, Rectangle var2) {
- return var2.y >= var1.y && var2.y + var2.height <= var1.y + var1.height ? 0 : var2.y + var2.height - (var1.y + var1.height) + 5;
- }
-
- public int getInitialDelay() {
- return this.enterTimer.getInitialDelay();
- }
-
- private int getPopupFitHeight(Rectangle var1, Component var2) {
- if (var2 != null) {
- for(Container var3 = var2.getParent(); var3 != null; var3 = ((Component)var3).getParent()) {
- if (var3 instanceof JFrame || var3 instanceof JDialog || var3 instanceof JWindow) {
- return this.getHeightAdjust(((Component)var3).getBounds(), var1);
- }
-
- if (var3 instanceof JApplet || var3 instanceof JInternalFrame) {
- if (this.popupFrameRect == null) {
- this.popupFrameRect = new Rectangle();
- }
-
- Point var4 = ((Component)var3).getLocationOnScreen();
- this.popupFrameRect.setBounds(var4.x, var4.y, ((Component)var3).getBounds().width, ((Component)var3).getBounds().height);
- return this.getHeightAdjust(this.popupFrameRect, var1);
- }
- }
- }
-
- return 0;
- }
-
- private int getPopupFitWidth(Rectangle var1, Component var2) {
- if (var2 != null) {
- for(Container var3 = var2.getParent(); var3 != null; var3 = ((Component)var3).getParent()) {
- if (var3 instanceof JFrame || var3 instanceof JDialog || var3 instanceof JWindow) {
- return this.getWidthAdjust(((Component)var3).getBounds(), var1);
- }
-
- if (var3 instanceof JApplet || var3 instanceof JInternalFrame) {
- if (this.popupFrameRect == null) {
- this.popupFrameRect = new Rectangle();
- }
-
- Point var4 = ((Component)var3).getLocationOnScreen();
- this.popupFrameRect.setBounds(var4.x, var4.y, ((Component)var3).getBounds().width, ((Component)var3).getBounds().height);
- return this.getWidthAdjust(this.popupFrameRect, var1);
- }
- }
- }
-
- return 0;
- }
-
- public int getReshowDelay() {
- return this.exitTimer.getInitialDelay();
- }
-
- private int getWidthAdjust(Rectangle var1, Rectangle var2) {
- return var2.x >= var1.x && var2.x + var2.width <= var1.x + var1.width ? 0 : var2.x + var2.width - (var1.x + var1.width) + 5;
- }
-
- void hideTipWindow() {
- if (this.tipWindow != null) {
- this.tipWindow.removeMouseListener(this);
- this.tipWindow.hide();
- this.tipWindow = null;
- this.tipShowing = false;
- this.timerEnter = 0L;
- this.tip.getUI().uninstallUI(this.tip);
- this.tip = null;
- this.insideTimer.stop();
- }
-
- }
-
- public boolean isEnabled() {
- return this.enabled;
- }
-
- public boolean isLightWeightPopupEnabled() {
- return this.lightWeightPopupEnabled;
- }
-
- public void mouseDragged(MouseEvent var1) {
- }
-
- public void mouseEntered(MouseEvent var1) {
- if (!this.tipShowing || this.lightWeightPopupEnabled || System.currentTimeMillis() - this.timerEnter >= 200L) {
- if (((EventObject)var1).getSource() != this.tipWindow) {
- JComponent var2 = (JComponent)((EventObject)var1).getSource();
- this.toolTipText = var2.getToolTipText(var1);
- this.preferredLocation = var2.getToolTipLocation(var1);
- this.exitTimer.stop();
- Point var3 = var1.getPoint();
- if (var3.x >= 0 && var3.x < var2.getWidth() && var3.y >= 0 && var3.y < var2.getHeight()) {
- if (this.insideComponent != null) {
- this.enterTimer.stop();
- this.insideComponent = null;
- }
-
- ((Component)var2).addMouseMotionListener(this);
- this.insideComponent = var2;
- if (this.tipWindow != null) {
- if (this.heavyWeightPopupEnabled) {
- return;
- }
-
- this.mouseEvent = var1;
- if (this.showImmediately) {
- this.showTipWindow();
- } else {
- this.enterTimer.start();
- }
- }
-
- }
- }
- }
- }
-
- public void mouseExited(MouseEvent var1) {
- if (!this.tipShowing || this.lightWeightPopupEnabled || System.currentTimeMillis() - this.timerEnter >= 200L) {
- boolean var2 = true;
- if (((EventObject)var1).getSource() == this.tipWindow) {
- Container var3 = this.insideComponent.getTopLevelAncestor();
- Rectangle var4 = this.tipWindow.getBounds();
- Point var5 = var1.getPoint();
- var5.x += var4.x;
- var5.y += var4.y;
- var4 = ((Component)var3).getBounds();
- var5.x -= var4.x;
- var5.y -= var4.y;
- var5 = SwingUtilities.convertPoint((Component)null, var5, this.insideComponent);
- if (var5.x >= 0 && var5.x < this.insideComponent.getWidth() && var5.y >= 0 && var5.y < this.insideComponent.getHeight()) {
- var2 = false;
- } else {
- var2 = true;
- }
- } else if (((EventObject)var1).getSource() == this.insideComponent && this.tipWindow != null) {
- Point var6 = SwingUtilities.convertPoint(this.insideComponent, var1.getPoint(), (Component)null);
- Rectangle var8 = this.insideComponent.getTopLevelAncestor().getBounds();
- var6.x += var8.x;
- var6.y += var8.y;
- var8 = this.tipWindow.getBounds();
- if (var6.x >= var8.x && var6.x < var8.x + var8.width && var6.y >= var8.y && var6.y < var8.y + var8.height) {
- var2 = false;
- } else {
- var2 = true;
- }
- }
-
- if (var2) {
- this.enterTimer.stop();
- if (this.insideComponent != null) {
- this.insideComponent.removeMouseMotionListener(this);
- }
-
- this.insideComponent = null;
- this.toolTipText = null;
- this.mouseEvent = null;
- this.hideTipWindow();
- this.exitTimer.start();
- }
-
- }
- }
-
- public void mouseMoved(MouseEvent var1) {
- JComponent var2 = (JComponent)((EventObject)var1).getSource();
- String var3 = var2.getToolTipText(var1);
- Point var4 = var2.getToolTipLocation(var1);
- if (var3 == null && var4 == null) {
- this.toolTipText = null;
- this.preferredLocation = null;
- this.mouseEvent = null;
- this.hideTipWindow();
- this.enterTimer.stop();
- this.exitTimer.start();
- } else {
- this.mouseEvent = var1;
- if ((var3 != null && var3.equals(this.toolTipText) || var3 == null) && (var4 != null && var4.equals(this.preferredLocation) || var4 == null)) {
- if (this.tipWindow != null) {
- this.insideTimer.restart();
- } else {
- this.enterTimer.restart();
- }
- } else {
- this.toolTipText = var3;
- this.preferredLocation = var4;
- if (this.showImmediately) {
- this.hideTipWindow();
- this.showTipWindow();
- } else {
- this.enterTimer.restart();
- }
- }
- }
-
- }
-
- public void mousePressed(MouseEvent var1) {
- this.hideTipWindow();
- this.enterTimer.stop();
- this.showImmediately = false;
- }
-
- public void registerComponent(JComponent var1) {
- ((Component)var1).removeMouseListener(this);
- ((Component)var1).addMouseListener(this);
- var1.registerKeyboardAction(this.postTipAction, this.postTip, 0);
- var1.registerKeyboardAction(this.hideTipAction, this.hideTip, 0);
- }
-
- public void setDismissDelay(int var1) {
- this.insideTimer.setInitialDelay(var1);
- }
-
- public void setEnabled(boolean var1) {
- this.enabled = var1;
- if (!var1) {
- this.hideTipWindow();
- }
-
- }
-
- public void setInitialDelay(int var1) {
- this.enterTimer.setInitialDelay(var1);
- }
-
- /** @deprecated */
- public void setLightWeightPopupEnabled(boolean var1) {
- this.lightWeightPopupEnabled = var1;
- }
-
- public void setReshowDelay(int var1) {
- this.exitTimer.setInitialDelay(var1);
- }
-
- public static ToolTipManager sharedInstance() {
- return sharedInstance;
- }
-
- void showTipWindow() {
- if (this.insideComponent != null && this.insideComponent.isShowing()) {
- if (this.enabled) {
- Point var2 = this.insideComponent.getLocationOnScreen();
- Dimension var3 = Toolkit.getDefaultToolkit().getScreenSize();
- Point var4 = new Point();
- this.hideTipWindow();
- this.tip = this.insideComponent.createToolTip();
- this.tip.setTipText(this.toolTipText);
- Dimension var1 = this.tip.getPreferredSize();
- if (this.insideComponent.getRootPane() == null) {
- this.tipWindow = new WindowPopup(this, frameForComponent(this.insideComponent), this.tip, var1);
- this.heavyWeightPopupEnabled = true;
- } else if (this.lightWeightPopupEnabled) {
- this.heavyWeightPopupEnabled = false;
- this.tipWindow = new JPanelPopup(this, this.tip, var1);
- } else {
- this.heavyWeightPopupEnabled = false;
- this.tipWindow = new PanelPopup(this, this.tip, var1);
- }
-
- this.tipWindow.addMouseListener(this);
- if (this.preferredLocation != null) {
- var4.x = var2.x + this.preferredLocation.x;
- var4.y = var2.y + this.preferredLocation.y;
- } else {
- var4.x = var2.x + this.mouseEvent.getX();
- var4.y = var2.y + this.mouseEvent.getY() + 20;
- if (var4.x + var1.width > var3.width) {
- var4.x -= var1.width;
- }
-
- if (var4.y + var1.height > var3.height) {
- var4.y -= var1.height + 20;
- }
- }
-
- if (!this.heavyWeightPopupEnabled) {
- if (this.popupRect == null) {
- this.popupRect = new Rectangle();
- }
-
- this.popupRect.setBounds(var4.x, var4.y, this.tipWindow.getBounds().width, this.tipWindow.getBounds().height);
- int var5 = this.getPopupFitHeight(this.popupRect, this.insideComponent);
- int var6 = this.getPopupFitWidth(this.popupRect, this.insideComponent);
- if (var5 > 0) {
- var4.y -= var5;
- }
-
- if (var6 > 0) {
- var4.x -= var6;
- }
- }
-
- this.tipWindow.show(this.insideComponent, var4.x, var4.y);
- this.insideTimer.start();
- this.timerEnter = System.currentTimeMillis();
- this.tipShowing = true;
- }
-
- }
- }
-
- public void unregisterComponent(JComponent var1) {
- ((Component)var1).removeMouseListener(this);
- var1.unregisterKeyboardAction(this.postTip);
- var1.unregisterKeyboardAction(this.hideTip);
- }
- }
-